package cn.itcast.service.user.impl;

import cn.itcast.dao.user.UserDao;
import cn.itcast.domain.User;
import cn.itcast.service.user.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("UserService")
public class UserServiceImp implements UserService {
    @Autowired
    private UserDao userDao;



    @Override
    public PageInfo findAllUser(int pageNum, int pageSize, String company_id) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list= userDao.findAllUser(company_id);
        PageInfo pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Override
    public User findById(String id) {
        User user=  userDao.findById(id);
        return user;
    }

    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public void delete(String id) {
        userDao.delete(id);
    }

    @Override
    public void saveUserRole(String userid, String[] roleIds) {
        /*根据用户的id删除以前所选择的角色*/
        userDao.deleteUserRole(userid);
        if (roleIds!=null){
        for (String roleId : roleIds) {
            userDao.saveUserRole(userid,roleId);
        }
        }
    }

    @Override
    public User findByUserName(String email) {
        User user= userDao.findByUserName(email);
        return user;
    }


}
